package Collection.hash.HashMap.HashCode;

import java.util.HashMap;

public class Student {
    private String name;
    private Integer age;

    public Student() {

    }

    public Student(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }
    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 17;
        result = prime * result + name.hashCode();
        result = prime * result + age;
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        final Student other = (Student) obj;
        if (name.equals(other.name)) {
            return false;
        }
        if (age.equals(other.age)) {
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        Student student1 = new Student("张三", 18);
        Student student2 = new Student("张三", 18);
        System.out.println(student1==student2);

        System.out.println(student1.hashCode());
        System.out.println(student2.hashCode());


        HashMap<String, Student> map = new HashMap(2);
        map.put("1", student1);
        map.put("2", student2);
        System.out.println(map.size());
    }
}